package edu.ynu.se.xiecheng.achitectureclass.controller;


import edu.ynu.se.xiecheng.achitectureclass.common.controller.LogicController;
import edu.ynu.se.xiecheng.achitectureclass.dao.SensorDao;
import edu.ynu.se.xiecheng.achitectureclass.dto.SensorDTO;
import edu.ynu.se.xiecheng.achitectureclass.entity.Sensor;
import edu.ynu.se.xiecheng.achitectureclass.service.SensorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("sensor")
public class SensorController extends LogicController<SensorService, SensorDao, Sensor, Long> {

    public SensorController(@Autowired SensorService service) {
        super(service);
    }

    @PostMapping
    public Boolean refreshSensorData() {
        try {
            return super.getService().refreshData();
        } catch (Exception e) {
            // 记录日志或处理异常
            e.printStackTrace();
            return false;
        }
    }

    @GetMapping
    public List<SensorDTO> getAllSensorsDTO() {
        return super.getService().getAllSensorsDTO();
    }
}
